﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BOM.entity;
using BOM.BaseData;
using System.Data;

namespace BOM.dao
{
    class MaterialgroupNew
    {
        //向表中插入数据
        public static bool InsertMaterialgroup()
        {
            Materialgroup materialgroup = new Materialgroup();
            string Str = "'" + materialgroup.Fnumber + "','" + materialgroup.Fname + "'," + MaterialList.JieDianID + "";
            string cmdText = "insert into materialgroup (fnumber,fname,fparentid) values (" + Str + ")";
            int i = DbService.executeSQL(cmdText);
            if (i == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        //根据ID 修改表中数据
        public static bool UpdateIDMaterialgroup(int fid)
        {
            Materialgroup materialgroup = new Materialgroup();
            string cmdText = "update materialgroup set fname = '" + materialgroup.Fname + "',fnumber = '" + materialgroup.Fnumber + "' where fid = " + fid + "";
            int values = DbService.executeSQL(cmdText);
            if (values == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        //根据ID查询数据
        public static DataTable QuryfidMaterialgroup(int fid)
        {
            string cmdText = "select * from materialgroup where fid = " + fid + "";
            DataTable table = DbService.getSQLTable(cmdText, "materialgroup");
            if (table.Rows.Count == 1)
            {
                return table;
            }
            else
            {
                return null;
            }
        }
        //根据分类名删除数据
        public static bool DeleteFnumberMaterialgroup(string fnumber)
        {
            string cmdText = "delete from materialgroup where fnumber = '" + fnumber + "'";
            int values = DbService.executeSQL(cmdText);
            if (values == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        //根据fid 和 fparentid 删除表 materialgroup数据
        public static bool DeleteFidMaterialgroup(int fid)
        {
            string cmdText = "delete from materialgroup where fid = " + fid + " or fparentid = " + fid + "";
            int i = DbService.executeSQL(cmdText);
            if (i >= 1)
            {
                return true;
            }
            else
            {
                return false;
            }

        }
        //根据fgroupid删除表 material数据
        public static bool DeleteFparentidMaterialgroup(int fparentid)
        {
            string cmdText = "delete from material where fgroupid = " + fparentid + "";
            int i = DbService.executeSQL(cmdText);
            if (i >= 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
